<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layout}">

<head>
	<meta charset="UTF-8">
	<title>血糖记录管理系统</title>
	<style scoped lang="less">

	</style>
</head>

<body>
	<div layout:fragment="fragment_body">
		<van-row>
			<van-calendar
			  ref="calendar"
			  :show-title="false"
			  :poppable="false"
			  :show-confirm="false"
			  :style="{ height: '450px' }"
			  :min-date="minDate"
			  :max-date="maxDate"
			  @select="selectDay"
			/>
		</van-row>
		<van-row>
			<van-button plain hairline size="small" icon="revoke" type="danger" @click="toToday" style="float: right;">返回当天</van-button>
		</van-row>
		<van-row style="margin-top:40px">
			<van-field
			  v-model="sugarValue"
			  center
			  label="血糖值"
			  placeholder="请输入..."
			>
			  <template #button>
			    <van-button size="small" type="primary" @click="saveRecord">保存</van-button>
			  </template>
			</van-field>
		</van-row>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		activeMenu: 'sugar',
		minDate: new Date(new Date().setFullYear(new Date().getFullYear()-10)),
		maxDate: new Date(), //new Date(new Date().setFullYear(new Date().getFullYear()+10)),
		sugarValue: '',
		nowDate: new Date(),
	}
	let vueMethods = {
		selectDay(dd){
			let that = this
			that.nowDate = dd
			that.sugarValue = ''
			that.getRecord()
		},
		toToday(){
			let that = this
			that.$refs.calendar.reset();
			that.nowDate = new Date()
			that.getRecord()
		},
		getRecord() {
			let that = this
			postRequst('/user/getSugarRecord', {date: getNowDate(that.nowDate)}, true).then(function (resp) {
				if(resp.status == 0){
					that.sugarValue = resp.data
				}
			})
		},
		saveRecord() {
			let that = this
			if(!that.sugarValue){
				that.$toast.fail('请填写');
				return false
			}
			let pp = {
				sugarValue: that.sugarValue,
				date: getNowDate(that.nowDate)
			}
			postRequst('/user/saveSugarRecord', pp, true).then(function (resp) {
				that.$toast.success(resp.msg);
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getRecord()
	}
</script>

</html>